/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package apus.action.phonenumber;

import apus.action.Action;
import apus.action.ActionResult;
import apus.entity.PhoneNumber;
import apus.exception.EntityNotFoundException;
import apus.persistence.PhoneNumberDAO;
import apus.services.ServiceLocator;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author 21vek
 */
public class PhoneNumberSearchAction implements Action{

    @Override
    public String getName() {
        return "phoneNumber.search";
    }

    @Override
    public ActionResult execute(HttpServletRequest request, HttpServletResponse response) {
        List <PhoneNumber> phoneNumberList;
        try {
            phoneNumberList = ServiceLocator.getService(PhoneNumberDAO.class).findBySubscriber(request.getParameter("name"));
        } catch (EntityNotFoundException e) {
            phoneNumberList = new ArrayList<PhoneNumber>();
        }
        request.setAttribute("phoneNumberList", phoneNumberList);
        return ActionResult.forward("/WEB-INF/View/search/phoneNumberSearch.jsp");
    }
    
}
